package com.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

@Entity
//使用默认表名
//@Table


@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class User extends BaseEntity{

    @Transient
    final Integer u_prohibit=1;
    @Transient
    final Integer u_manager=0;
    @Transient
    final Integer u_teacher=1;
    @Transient
    final Integer u_student=2;

    private String nickName;

    private String userName;

    private String email;

    private String phone;

    private String password;

    private String avatar;

    private Integer type;

    private String salt;

    private boolean applyTeacher;

    //存入数据库的date只带日期不带时间
    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;

    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;

    @OneToMany(mappedBy = "teacher")
    private List<Course> courses;

    @ManyToMany(mappedBy = "students")
    private List<Course> enrolledCourses;

    @OneToMany(mappedBy = "student")
    private List<Result> results;

    @OneToMany(mappedBy = "student")
    private List<Applicant> applicants;

    @JsonManagedReference
    public List<Course> getCourses() {
        return courses;
    }

    public void setCourses(List<Course> courses) {
        this.courses = courses;
    }

    @JsonIgnore
    public List<Course> getEnrolledCourses() {
        return enrolledCourses;
    }

    public void setEnrolledCourses(List<Course> enrolledCourses) {
        this.enrolledCourses = enrolledCourses;
    }

    @JsonManagedReference
    public List<Result> getResults() {
        return results;
    }

    public void setResults(List<Result> results) {
        this.results = results;
    }

    @JsonManagedReference
    public List<Applicant> getApplicants() {
        return applicants;
    }

    public void setApplicants(List<Applicant> applicants) {
        this.applicants = applicants;
    }
}
